/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.stat.model.parameter;

import org.math.data.DataValue;
import org.math.data.Dimension;

/**
 *
 * @author stewari1
 */
public class Parameter {

    /** Field description */
    private boolean parameterEstimated = false;

    /** Field description */
    private final String name;

    /** Field description */
    private DataValue value;

    /** Field description */
    private DataValue estimatedValue;

    /**
     * Constructs ...
     *
     * @param name description
     * @param value description
     */
    public Parameter(String name, DataValue value) {

        this.name           = name;
        this.value          = value;
        this.estimatedValue = value.copy();
    }

    /**
     * this would help identify the type of the parameter value which is
     * of the type used in its value.
     * @return
     */
    public Dimension getParamDimension() {
        return this.value.getDimension();
    }

    public DataValue getEstimatedValue() throws ParamNotEstimatedException {

        if (estimatedValue == null) {
            throw new ParamNotEstimatedException("Parameter has not been estimated yet.");
        }

        return estimatedValue;
    }

    /**
     * should only be used by the internal library classes. Never directly be called
     * by the developer.
     * @param estimatedValue
     */
    public void setEstimatedValue(DataValue estimatedValue) {

        this.estimatedValue     = estimatedValue;
        this.parameterEstimated = true;
    }

    public void setEstimatedValue(double estimatedValue) {

        this.estimatedValue.setValue(estimatedValue);

        this.parameterEstimated = true;
    }

    public DataValue getValue() throws UnknownParamValueException {

        if (!this.parameterEstimated) {
            throw new UnknownParamValueException("Parameter value is unknown.");
        }

        return value;
    }

    public void setValue(DataValue value) {
        this.value = value;
    }

    /**
     * convenience method
     * @param value
     */
    public void setValue(double value) {

        this.value.setValue(value);

        this.parameterEstimated = true;
    }

    public String getName() {
        return name;
    }
}
